<?php
namespace Action;
use HY\Action;
!defined('HY_PATH') && exit('HY_PATH not defined.');
class Index extends HYBBS {
	public function __construct(){
		parent::__construct();
		//{hook a_index_init}
		if(!IS_LOGIN){
			if(IS_AJAX && IS_POST){
				die($this->json(array('error'=>false,'info'=>'请登录后再操作')));
			}
			else{
				header("location: ". HYBBS_URLA('user','login'));
				die;
			}

		}
	}
	public function Index(){
		//{hook a_index_index_1}
		//$this->v('title',$this->conf['title']);
		exec('WMIC logicaldisk where "name=\''.C('watchDrive').'\'" get FreeSpace,size /value',$out);
		exec('WMIC os get TotalVisibleMemorySize,FreePhysicalMemory /value',$out);
		$dfreespace = sprintf('%.2f',explode('=',$out[2])[1]/1024/1024/1024);
		$dtotalspace = sprintf('%.2f',explode('=',$out[3])[1]/1024/1024/1024);
		$mfreespace = sprintf('%.2f',explode('=',$out[9])[1]/1024/1024);
		$mtotalspace = sprintf('%.2f',explode('=',$out[10])[1]/1024/1024);
		//exec('ping 127.0.0.1',$out);
//		passthru('chcp 437',$o);
//		passthru('ping 127.0.0.1',$o);
//		passthru('tasklist',$o);
//		$this->json($o);
		$dmod = sprintf('%.2f',($dtotalspace-$dfreespace)/$dtotalspace*100);
		$mmod = sprintf('%.2f',($mtotalspace-$mfreespace)/$mtotalspace*100);
		$this->v('dfreespace',$dfreespace);
		$this->v('dtotalspace',$dtotalspace);
		$this->v('mfreespace',$mfreespace);
		$this->v('mtotalspace',$mtotalspace);
		$this->v('dmod',$dmod);
		$this->v('mmod',$mmod);
		$this->view = 'CQQ';
		$this->v("title","画方");
        $this->v("title2","全流量加速系统");
		$this->display('index');
	}
	public function process(){
		$key = X('post.key');
		$out = [];
		$re = [];
		exec('tasklist',$out);
		if($key == 'FHL'){
			//$this->json(['tasklist'=>1]);
			foreach($out as $k=>$v){
				if(!strpos($v,'t0.exe')&&strpos($v,'FengHoLn')===0){
					$tmp = preg_split("/\s+/",$v);
					array_push($re,['name'=>str_replace('FengHoLn','中转进程',$tmp[0]),'id'=>$tmp[1],'size'=>$tmp[4].$tmp[5]]);
				}
			}

		}elseif($key == 'FTP'){
			foreach($out as $k=>$v){
				if(strpos($v,'FTPServer')===0){
					$tmp = preg_split("/\s+/",$v);
					array_push($re,['name'=>str_replace('FTP','文件同步',$tmp[0]),'id'=>$tmp[1],'size'=>$tmp[4].$tmp[5]]);
				}
			}
		}elseif($key == 'MAIN'){
			foreach($out as $k=>$v){
				if(strpos($v,'t0.exe')>0&&strpos($v,'FengHoLn')===0){
					$tmp = preg_split("/\s+/",$v);
					array_push($re,['name'=>str_replace('FengHoLn','高速链路',$tmp[0]),'id'=>$tmp[1],'size'=>$tmp[4].$tmp[5]]);
				}
			}
		}
		$this->json($re);
	}
	
	
	//{hook a_index_fun}
}
